Graphics Device Interface Plus |
GDI+ is very similar to GDI. GDI+ was designed to produce high quality of the graphics at the cost of speed. One of the main differences is that you do not need to select a graphics object such as a pen or brush before using it. GDI+ es muy semejante a GDI. GDI+ fue diseñada para producir gráficos de alta calidad al costo de velocidad. Una de las principales diferencias es que usted no necesita seleccionar un objeto de gráficos tal como una pluma o una brocha antes de usarlo. |
Wintempla and GDI+ |
To use GDI+ in a Wintempla project you need to be sure that the proper header files are included. Open the stdafx.h file and be sure that WIN_GDI_PLUS_ON is defined as shown below. Para usar GDI+ en un proyecto de Wintempla usted necesita asegurarse que los archivos de encabezado necesarios están incluidos. Abra el archivo stdafx.h y asegúrese que WIN_GDI_PLUS_ON esté definido como se muestra debajo. |
stdafx.h |
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #pragma once /************************CONFIGURATION FILE ****************************/ //_________________________________________ GDI+ #define WIN_GDI_PLUS_ON //_________________________________________ MIDI, Audio Card DAC's and ADC's (or GDI Game for timers) //#define WIN_DAC_ADC_SUPPORT ... |
Problem 1 |
Create a Window Application (using Wintempla) called MyQuality to test GDI+. After creating the project, open Wintempla, double click anywhere in the interface, and set the Paint event as shown below. Cree una aplicación de Ventana (usando Wintempla) llamada MyQuality para probar GDI+. Después de crear el proyecto abra Wintempla, haga doble clic sobre cualquier parte de la interface y fije el evento de Paint como se muestra debajo. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { //_______________________________ GDI is active CG::Gdi gdi(hWnd, true, false); } |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { //_______________________________ GDI+ is active CG::Gdi gdi(hWnd, true, true); } |
Problem 2 |
Modify the Window_Paint function of the MyQuality project to draw two ellipses: one using high speed, and the other one using high quality. Modifique la función Window_Paint del proyecto MyQuality para dibujar dos elipses: una usando alta velocidad, y la otra usando alta calidad. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::SolidBrush brush(Gdiplus::Color(255, 0, 0, 0)); // Alpha, Red, Green, Blue //___________________________________________ High Speed gdi.Plus.SetSmoothingMode(Gdiplus::SmoothingModeHighSpeed); gdi.Plus.FillEllipse(&brush, 10, 0, 200, 100); //___________________________________________ High Quality gdi.Plus.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); gdi.Plus.FillEllipse(&brush, 10, 120, 200, 100); } |
Problem 3 |
Modify the Window_Paint function of the MyQuality project to use FillClosedCurve. Modifique la función Window_Paint del proyecto MyQuality para usar FillClosedCurve. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 0, 0)); // Alpha, Red, Green, Blue gdi.Plus.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); Gdiplus::PointF point[3]; point[0].X = 10.0f; point[0].Y = 20.0f; // point[1].X = 100.0f; point[1].Y = 20.0f; // point[2].X = 100.0f; point[2].Y = 100.0f; // gdi.Plus.FillClosedCurve(&brush, point, 3); } |
Problem 4 |
Modify the Window_Paint function of the MyQuality project to show a jpg file. Modifique la función Window_Paint del proyecto MyQuality para mostrar un archivo jpg . |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::Image image(L"Grapes.jpg"); gdi.Plus.DrawImage(&image, 60, 10); } |
Problem 5 |
Modify the Window_Paint function of the MyQuality project to draw: a line, a rectangle and a curve. Modifique la función Window_Paint del proyecto MyQuality para dibujar: una línea, un rectángulo y una curva |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::Pen penBlue(Gdiplus::Color(255, 0, 0, 255)); Gdiplus::Pen penRed(Gdiplus::Color(255, 255, 0, 0)); //_____________________________________________________ Line gdi.Plus.DrawLine(&penBlue, 200, 10, 400, 10); //_____________________________________________________ Rectangle gdi.Plus.DrawRectangle(&penRed, 110, 110, 100, 50); //_____________________________________________________ Curve Gdiplus::Point points[] = { Gdiplus::Point(30, 100), Gdiplus::Point(50, 80), Gdiplus::Point(100, 20), Gdiplus::Point(150, 80), Gdiplus::Point(200, 100) }; gdi.Plus.DrawCurve(&penBlue, points, 5); } |
Problem 6 |
Modify the Window_Paint function of the MyQuality project to draw two bezier curves. Modifique la función Window_Paint del proyecto MyQuality para dibujar dos curvas bezier. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::Pen pen(Gdiplus::Color(255, 0, 0, 255)); //_____________________________________________ One Bezier Gdiplus::Point p1(10, 100); // start point Gdiplus::Point c1(100, 10); // first control point Gdiplus::Point c2(150, 150); // second control point Gdiplus::Point p2(200, 100); // end point gdi.Plus.DrawBezier(&pen, p1, c1, c2, p2); //_____________________________________________ Two Beziers Gdiplus::Point p[] = { //______________ 1 Gdiplus::Point(10, 200), // start point of first spline Gdiplus::Point(75, 110), // first control point of first spline Gdiplus::Point(80, 150), // second control point of first spline Gdiplus::Point(100, 250), // end point of first spline and //______________ 2 Gdiplus::Point(125, 180), // first control point of second spline Gdiplus::Point(175, 300), // second control point of second spline Gdiplus::Point(200, 180) // end point of second spline }; gdi.Plus.DrawBeziers(&pen, p, 7); } |
Problem 7 |
Modify the Window_Paint function of the MyQuality project to draw text. Modifique la función Window_Paint del proyecto MyQuality para dibujar texto. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::Pen pen(Gdiplus::Color(255, 0, 0, 255)); Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 255, 0, 255)); Gdiplus::FontFamily fontFamily(L"Times New Roman"); Gdiplus::Font font(&fontFamily, 64, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); //__________________________________________ Regular gdi.Plus.SetTextRenderingHint(Gdiplus::TextRenderingHintSingleBitPerPixel); gdi.Plus.DrawString(L"Hello", -1, &font, Gdiplus::PointF(10.0f, 10.0f), &solidBrush); //__________________________________________ AntiAlias gdi.Plus.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); gdi.Plus.DrawString(L"Hola", -1, &font, Gdiplus::PointF(10.0f, 130.0f), &solidBrush); //__________________________________________ Tabs Gdiplus::RectF rectF(10.0f, 240.0f, 650.0f, 600.0f); Gdiplus::StringFormat stringFormat; Gdiplus::REAL tabs[] = { 100.0f, 100.0f, 100.0f }; stringFormat.SetTabStops(0.0f, 3, tabs); gdi.Plus.DrawString(L"1\t2\t3", -1, &font, rectF, &stringFormat, &solidBrush); } |
Problem 8 |
Modify the Window_Paint function of the MyQuality project to draw rotated text. Modifique la función Window_Paint del proyecto MyQuality para dibujar texto rotado. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::FontFamily fontFamily(L"Times New Roman"); Gdiplus::Font font(&fontFamily, 64, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); Gdiplus::SolidBrush brush(Gdiplus::Color(255, 0, 100, 0)); Gdiplus::REAL x = width / 2.0f; Gdiplus::REAL y = height / 2.0f; Gdiplus::PointF pointF(0.0f, 0.0f); gdi.Plus.TranslateTransform(x, y); gdi.Plus.RotateTransform(270); gdi.Plus.DrawString(L"Hello", -1, &font, pointF, &brush); gdi.Plus.ResetTransform(); } |
Problem 9 |
Modify the Window_Paint function of the MyQuality project to test the font height. Modifique la función Window_Paint del proyecto MyQuality para probar la altura de la fuente. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::FontFamily fontFamily(L"Times New Roman"); Gdiplus::Font font(&fontFamily, 32, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); Gdiplus::SolidBrush brush(Gdiplus::Color(255, 20, 100, 0)); Gdiplus::PointF position(0.0f, 0.0f); Gdiplus::REAL deltaY = font.GetHeight(0.0f); gdi.Plus.DrawString(L"Uno", -1, &font, position, &brush); position.Y += deltaY; // gdi.Plus.DrawString(L"Dos", -1, &font, position, &brush); position.Y += deltaY; // gdi.Plus.DrawString(L"Tres", -1, &font, position, &brush); position.Y += deltaY; // gdi.Plus.DrawString(L"Cuatro", -1, &font, position, &brush); position.Y += deltaY; } |
Problem 10 |
Modify the Window_Paint function of the MyQuality project to test the types of pens. Modifique la función Window_Paint del proyecto MyQuality para probar los tipos de plumas. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::Pen blackPen(Gdiplus::Color(255, 0, 0, 0), 1); Gdiplus::Pen greenPen(Gdiplus::Color(255, 0, 255, 0), 10); greenPen.SetAlignment(Gdiplus::PenAlignmentCenter); //_____________________________________________________ Line gdi.Plus.DrawLine(&greenPen, 10, 100, 100, 50); gdi.Plus.DrawLine(&blackPen, 10, 100, 100, 50); //_____________________________________________________ Line gdi.Plus.DrawRectangle(&greenPen, 10, 100, 50, 50); gdi.Plus.DrawRectangle(&blackPen, 10, 100, 50, 50); //____________________________________________________ Pen Caps Gdiplus::Pen penCaps(Gdiplus::Color(255, 0, 0, 255), 8); penCaps.SetStartCap(Gdiplus::LineCapArrowAnchor); penCaps.SetEndCap(Gdiplus::LineCapRoundAnchor); gdi.Plus.DrawLine(&penCaps, 20, 175, 300, 175); //____________________________________________________ Pen Dash Gdiplus::REAL dashValues[4] = { 5, 2, 15, 4 }; blackPen.SetDashPattern(dashValues, 4); gdi.Plus.DrawLine(&blackPen, Gdiplus::Point(25, 25), Gdiplus::Point(405, 25)); } |
Problem 11 |
Modify the Window_Paint function of the MyQuality project to test paths (a path is composed of lines, curves, etc.) Modifique la función Window_Paint del proyecto MyQuality para probar los paths (un path está compuesto de líneas, curvas, etc.) |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); Gdiplus::GraphicsPath path; Gdiplus::Pen penJoin(Gdiplus::Color(255, 0, 0, 255), 8); path.StartFigure(); path.AddLine(Gdiplus::Point(50, 200), Gdiplus::Point(100, 200)); path.AddLine(Gdiplus::Point(100, 200), Gdiplus::Point(100, 250)); penJoin.SetLineJoin(Gdiplus::LineJoinBevel); gdi.Plus.DrawPath(&penJoin, &path); } |
Problem 12 |
Modify the Window_Paint function of the MyQuality project to test brushs. You will need to have the file Texture.jpg in your project folder. Modifique la función Window_Paint del proyecto MyQuality para probar los brochas. Usted necesitara tener le archivo Texture.jpg en la carpeta de su proyecto. |
MyQuality.cpp |
... void MyQuality::Window_Paint(Win::Event& e) { CG::Gdi gdi(hWnd, true, true); //__________________________________________________ Texture Brush Gdiplus::Image image(L"Texture.jpg"); Gdiplus::TextureBrush textureBrush(&image); Gdiplus::Pen texturedPen(&textureBrush, 30); gdi.Plus.DrawImage(&image, 10, 10, image.GetWidth(), image.GetHeight()); gdi.Plus.DrawEllipse(&texturedPen, 240, 20, 100, 160); //__________________________________________________ Solid Brush Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 255, 0, 0)); gdi.Plus.FillEllipse(&solidBrush, 0, 200, 100, 260); //__________________________________________________ Solid Hatch Gdiplus::HatchBrush hBrush(Gdiplus::HatchStyleHorizontal, Gdiplus::Color(255, 0, 120, 0), Gdiplus::Color(255, 0, 0, 0) ); gdi.Plus.FillEllipse(&hBrush, 200, 320, 300, 160); //__________________________________________________ Solid Image Brush textureBrush.SetTransform(&Gdiplus::Matrix(75.0 / 640.0, 0.0f, 0.0f, 75.0 / 480.0, 0.0f, 0.0f)); gdi.Plus.FillEllipse(&textureBrush, Gdiplus::Rect(400, 150, 150, 250)); //_________________________________________________ Gradient Brush Gdiplus::LinearGradientBrush linGrBrush( Gdiplus::Point(0, 10), Gdiplus::Point(200, 10), Gdiplus::Color(255, 255, 0, 0), // Red Gdiplus::Color(255, 0, 0, 255) // Blue ); Gdiplus::Pen pen(&linGrBrush); gdi.Plus.FillEllipse(&linGrBrush, 200, 230, 200, 100); gdi.Plus.FillRectangle(&linGrBrush, 90, 355, 500, 30); } |